<template>
	<view class="equipment">
		<view class="equipment-navbar">
			<!-- <u-navbar placeholder title="设备" autoBack leftIconColor="#fff" bgColor="#2980f7"
				:titleStyle="{color:'#fff'}">
			</u-navbar> -->
			<view class="equipment-add">
				<view class="">
					<u-tabs :list="list1" @click="handleTabs" :inactiveStyle="{
				    color: '#fff',
				    transform: 'scale(1)'
				}" lineColor="#fff" :activeStyle="{
				    color: '#fff',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'}"></u-tabs>
				</view>
				<view class="right" v-if="!activeTab">
					<view class="add-btn" @tap="isAdd=!isAdd">
						添加设备 +
					</view>
					<view class="mask" v-show="isAdd" @tap="isAdd=false">
						<view class="position-add">
							<view class="item-add" @tap="handleScanCode">
								扫码绑定
							</view>
							<view class="item-add" @tap="handleAdd">
								添加设备
							</view>
						</view>
					</view>
				</view>

				<view class="right" v-else @tap="handleDial">拨号设置</view>
			</view>
			<dropDownMenu @handleFilter="handleFilter"></dropDownMenu>
		</view>
		<scroll-view scroll-y="true">
			<view class="equipment-main">
				<view class="equipment_box">
					<view class="equipment_list">
						<view v-for="(item,index) in list" :key="index">
							<view class="equipmentItem">
								<view class="equipment_item black">
									<!-- @click="jump(`/pageC/equipmentProfit?name=${item.sn}&onlineCode=${item.onlineCode}`)" -->
									<view class="l"
										@click="jump(`/pageC/equipmentDetail?name=${item.sn}&onlineCode=${item.onlineCode}`)">
										<image :src="$fun.imgUrl(item.image)" mode=""></image>
										<view class="center_info">
											<view class="text1">
												{{item.desc ? item.desc :''}}
											</view>
											<view class="text2">
												{{item.addrIspCode}}
											</view>
											<view class="text">
												<view class="b" v-if="item.onlineCode==0">

												</view>
												<view class="b" style="background: gray;"
													v-else-if="item.onlineCode==1">

												</view>
												<view class="b" style="background: red;" v-else>

												</view>
												<view class="info">
													{{item.sn}}
												</view>
											</view>

										</view>
									</view>
									<view class="r">
										<view class="info">
											<text>+{{item.income}}</text>
											<text>总{{item.totalIcome}}</text>
											<!-- <text -->
											<!-- @click="jump(`/pageC/${item.type==0?'equipmentDetail':'equipmentDetail1'}?name=${item.sn}&onlineCode=${item.onlineCode}`)">查看详情</text> -->
										</view>
										<image src="/static/newProject/equipment/icon_r.png" mode=""></image>
									</view>
								</view>
								<u-line v-if="activeTab"></u-line>
								<view class="item-bottom" v-if="activeTab">
									<navigator class="item-icon"
										:url="`/pageC/dialInfo/dialInfo?sn=${item.sn}&netType=${item.netType}`">
										<!-- <view class="item-icon" @tap=""> -->
										<view class="">
											<u-icon name="minus-circle" color="#2979ff" size="18"></u-icon>
										</view>
										<view class="item-text">
											调整线路
										</view>
										<!-- </view> -->
									</navigator>

									<view class="item-icon" @tap="handleDialResult(item)">
										<view class="">
											<u-icon name="question-circle" color="#2979ff" size="18"></u-icon>
										</view>
										<view class="item-text">
											拨号信息
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- <view v-else>
				<view class="noneDate_box">
					<image src="/static/newProject/equipment_none.png" mode=""></image>
					<view class="button" @click="jump('./add')">
						去绑定 [+]
					</view>
				</view>
			</view> -->
		</scroll-view>
		<u-modal :show="lineModal" title="提示" showCancelButton @cancel="lineModal = false">
			<view class="">是否清退当前线路?</view>
		</u-modal>
		<view class="" v-if="!list.length" style="display: flex;justify-content: center;margin-top: 300rpx;">
			<image src="@/static/noneLine.png" mode="heightFix"></image>
		</view>

		<!-- <u-empty mode="data" v-if="!list.length" text="暂无设备"></u-empty> -->
		<!-- #ifdef APP -->
		<!-- <view style="height: 170upx;">

		</view>
		<TabBar :tabBarShow="1"></TabBar> -->
		<!-- #endif -->
	</view>
</template>

<script>
	import headerTop from "@/components/dacizi-headtag/dacizi-headtag.vue"
	export default {
		components: {
			headerTop
		},
		data() {
			return {
				filterList: [{
					lable: '全部',
					value: -1
				}, {
					lable: '全部',
					value: -1
				}],
				show: false,
				lineModal: false,
				list1: [{
					name: '设备',
				}, {
					name: '多拨号',
				}],
				// equipment: [{
				// 		title: '全部',
				// 		value: '-1',
				// 		color: '#FFFFFF'
				// 	},
				// 	{
				// 		title: '在线',
				// 		value: '0',
				// 		color: '#00FF00'
				// 	},
				// 	{
				// 		title: '离线',
				// 		value: '1',
				// 		color: '#A0A0A0'
				// 	},
				// 	{
				// 		title: '故障',
				// 		value: '2',
				// 		color: '#FF0000'
				// 	},
				// ],
				equipmentInfo: {
					count: 0
				},
				list: [],
				page: 1,
				limit: 20,
				activeIndex: 0,
				activeName: '全部分组',
				activeType: '',
				group_id: -1,
				pipeType: '',
				GroupList: [],
				GroupType: [],
				count: 0,
				activeTab: 0,
				isAdd: false,
				vlan: -1
			}
		},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			setTimeout(() => {
				this.getGroupList()
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			if (this.page != 1) {
				this.getUserSnList(this.page, this.limit)
			}
		},
		onNavigationBarButtonTap(e) {
			this.$fun.jump('/pageC/add')
		},
		// 分享好友
		onShareAppMessage() {
			return {
				title: '鲸算网云',
				path: JSON.parse(uni.getStorageSync('gitH5Qrcode')),
			}
		},
		// 分享朋友圈
		onShareTimeline() {
			return {
				title: '鲸算网云',
				query: JSON.parse(uni.getStorageSync('gitH5Qrcode')),
			}
		},
		onShow() {
			this.list = []
			this.page = 1
			this.getGroupList()
			// #ifdef APP
			// uni.hideTabBar()
			// #endif
		},
		onHide() {
			this.isAdd = false
		},
		methods: {
			handleFilter(value) {
				this.page = 1,
					this.limit = 20
				this.list = []
				this.filterList = value
				this.getUserSnList()
			},
			// 拨号信息
			handleDialResult(item) {
				this.$fun.jump(`/pageC/dialResult/dialResult?sn=${item.sn}&netType=${item.netType}`)
			},
			handleScanCode() {
				let _that = this
				console.log('111111')
				//#ifdef H5
				this.$fun.msg('H5暂不支持扫码！')
				//#endif
				// #ifndef H5
				uni.scanCode({
					success: function(res) {
						_that.$fun.jump(`/pageC/add?sn=${res.result}`)
					}
				});
				// #endif
			},
			handleAdd() {
				this.$fun.jump('/pageC/add')
			},
			// 拨号设置
			handleDial() {
				this.$fun.jump('/pageC/DialSetting/DialSetting')
			},
			// 点击tabs
			handleTabs(item) {
				this.page = 1,
					this.limit = 20
				if (item.index) {
					this.pipeType = 3
					this.vlan = 1
				} else {
					this.pipeType = -1
					this.vlan = -1
				}
				this.list = []
				this.getUserSnList()
				this.activeTab = item.index
			},
			// changeActiveName(str) {
			// 	let data = []
			// 	for (var i = 0; i < this[str].length; i++) {
			// 		data.push(this[str][i].name)
			// 	}
			// 	uni.showActionSheet({
			// 		itemList: data,
			// 		success: (res) => {
			// 			console.log(res)
			// 			if (str == 'GroupList') {
			// 				this.group_id = this.GroupList[res.tapIndex].id
			// 				this.activeName = this.GroupList[res.tapIndex].name
			// 				this.count = this.GroupList[res.tapIndex].num
			// 			} else {
			// 				this.pipeType = this[str][res.tapIndex].id
			// 				this.activeType = this[str][res.tapIndex].name
			// 			}
			// 			this.list = []
			// 			this.page = 1
			// 			this.getUserSnList(this.page, this.limit)
			// 			// this.getGroupList()
			// 		},
			// 		fail: function(res) {
			// 			console.log(res.errMsg);
			// 		}
			// 	});
			// },
			getUserSnList(page, limit) {
				this.$fun.ajax.post('butt/userSnList', {
					page: this.page,
					limit: this.limit,
					onlineCode: this.filterList[0].value,
					group_id: this.group_id,
					pipeType: this.filterList[1].value,
					vlan: this.vlan
				}).then(res => {
					if (res.data.list.length > 0) {
						this.list.push(...res.data.list);
						this.addressList = res.data
						this.page++
					} else {
						if (this.page != 1) {
							this.$fun.msg('没有更多数据了...')
						}
					}
					// this.equipmentInfo = res.data
				})
			},
			clickItem(item, index) {
				this.activeIndex = index
				this.list = []
				this.page = 1
				this.getUserSnList(this.page, this.limit)
			},
			async getGroupList(onlineCode = -1) {
				// await this.$fun.ajax.post('butt/groupList', {
				// 	onlineCode,
				// }).then(res => {
				// 	this.GroupList = res.data
				// 	this.count = res.data[0].num
				// 	this.activeName = res.data[0].name
				// })
				// await this.$fun.ajax.post('butt/typeList', {
				// 	onlineCode,
				// }).then(res => {
				// 	const data1 = []
				// 	res.data.forEach((val) => {
				// 		data1.push({
				// 			lable: val.name,
				// 			value: val.id
				// 		})
				// 	})
				// 	this.options[1] = data1
				// })
				// await this.$fun.ajax.post('butt/typeList', {
				// 	onlineCode,
				// }).then(res => {
				// 	this.GroupType = res.data
				// 	this.activeType = res.data[0].name
				// 	this.pipeType = res.data[0].id
				// })
				await this.getUserSnList(this.page, this.limit)
			},
			jump(url) {
				this.$fun.jump(url)
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F9FF;
	}

	.equipment {
		.equipment-navbar {
			background-color: #0066FF;

			.equipment-add {
				position: relative;
				height: 100rpx;
				display: flex;
				justify-content: space-between;
				align-items: flex-end;
				padding-bottom: 15rpx;
				padding-right: 20rpx;

				.right {
					position: relative;
					font-size: 14px;
					color: #fff;
					padding-bottom: 20rpx;

					.mask {
						background-color: transparent;
						position: absolute;
						z-index: 999;
						top: 100%;
						left: 0;
						width: 100%;
						height: 1000rpx;

						.position-add {
							position: absolute;
							z-index: 9999;
							top: 0;
							right: 0;
							background-color: #f9f9f9;
							width: 180rpx;
							color: #000;
							border-radius: 10rpx;
							padding: 5rpx;

							.item-add {
								padding: 20rpx 0;
								font-size: 14px;
								font-weight: 600;
								text-align: center;
							}
						}
					}
				}
			}
		}

		.equipment-main {
			position: relative;
		}

		.top_equipment {
			padding-top: 20rpx;
			width: 100%;
			height: 88rpx;
			background: #2980f7;
			box-sizing: border-box;
			padding: 0 0rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.top_item {
				width: 25%;
				height: 88rpx;
				position: relative;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				font-family: Microsoft YaHei;
				color: #fff;
				font-size: 30rpx;
				// border: 1rpx solid #2b7cff;
				// border-radius: 10rpx;

				.num {
					margin-bottom: 20rpx;
					font-weight: bold;
				}

				.circular {
					position: absolute;
					top: 15rpx;
					right: 15rpx;
					width: 15rpx;
					height: 15rpx;
					border-radius: 50%;
				}
			}

			.active {
				// border-radius: 10rpx;
				background: #fff;
				color: #ffa136;
			}
		}

		.top_box {
			background: #FFFFFF;
			display: flex;
			padding: 0 32rpx;
			height: 95rpx;
			align-items: center;
			justify-content: space-between;

			.l {
				display: flex;
				align-items: center;

				image {
					margin-left: 13rpx;
					margin-right: 10rpx;
					width: 33rpx;
					height: 38rpx;
				}

				text {
					font-size: 32rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					color: #333333;
				}
			}

			.r {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #2980F7;

				image {
					margin-right: 10rpx;
				}
			}
		}

		.equipment_box {
			padding: 0rpx 30rpx;


			.cenetr_box {
				margin-top: 29rpx;
				height: 80rpx;
				background: #EEEEEE;
				border-radius: 10px;
				display: flex;
				justify-content: space-between;
				align-items: center;
				// padding: 0 30rpx;
				box-sizing: border-box;

				.l {
					font-size: 20rpx;
					font-family: Microsoft YaHei;
					font-weight: bold;
					color: #333333;
				}

				.r {
					width: 336rpx;
					height: 80rpx;
					background: #2980F7;
					border-radius: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					color: #FFFFFF;

					image {
						margin-left: 90rpx;
						width: 24rpx;
						height: 14rpx;
					}
				}
			}


		}

		.equipment_list {
			margin-top: 20rpx;

			.equipmentItem {
				background-color: #fff;
				padding: 25rpx 30rpx;
				border-radius: 10rpx;
				margin-bottom: 20rpx;
				width: 100%;
				box-sizing: border-box;

				.item-bottom {
					display: flex;
					justify-content: space-between;
					font-size: 12px;
					margin-top: 10rpx;
				}

				.item-icon {
					display: flex;
					align-items: center;

					.item-text {
						margin-left: 5rpx;
					}
				}
			}

			.equipment_item {
				display: flex;
				justify-content: space-between;

				.l {
					display: flex;

					image {
						width: 165rpx;
						height: 165rpx;
						border-radius: 10rpx;
					}

					.center_info {
						margin-left: 14rpx;
						display: flex;
						flex-direction: column;
						width: 300rpx;

						.text1 {
							font-size: 32rpx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
						}

						.text2 {
							margin-top: 20rpx;
							font-size: 24rpx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #999999;
						}

						.text {

							display: flex;
							align-items: center;

							.b {
								width: 28rpx;
								height: 8rpx;
								background: #55B953;
								border-radius: 4rpx;
							}

							.info {
								width: 277rpx; //固定宽度
								overflow: hidden; //溢出隐藏
								white-space: nowrap; //不换行
								text-overflow: ellipsis; //显示...
								font-size: 24rpx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #999999;
							}
						}

					}
				}

				.r {
					display: flex;
					justify-content: flex-end;
					align-items: center;

					.info {
						height: 100%;
						display: flex;
						flex-direction: column;
						justify-content: flex-start;
						text-align: right;

						text:nth-child(1) {
							font-size: 24rpx;
							font-family: Microsoft YaHei;
							font-weight: 400;
							color: #E91A4B;
						}

						text:nth-child(2) {
							margin-top: 30rpx;
							font-size: 24rpx;
							font-family: Adobe Heiti Std;
							font-weight: normal;
							color: #999999;
						}

						text:nth-child(3) {
							font-size: 24rpx;
							font-family: Adobe Heiti Std;
							font-weight: normal;
							color: #0066FF;
							margin: 10rpx 0;
						}

					}

					image {
						margin-left: 22rpx;
						width: 14rpx;
						height: 24rpx;
					}
				}
			}

			.gray {
				background: #F6F6F6;
				color: #CCCCCC;
			}

			.black {
				// background: #F6F6F6;
				color: #333333;
			}
		}

	}

	.noneDate_box {
		margin-top: 126rpx;
		text-align: center;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		image {
			width: 309rpx;
			height: 317rpx;
		}

		.button {
			margin: 30rpx 0;
			width: 200rpx;
			height: 60rpx;
			background: linear-gradient(-30deg, #FE555A 0%, #F99E35 100%);
			border-radius: 30rpx;
			font-size: 22rpx;
			font-family: Microsoft YaHei;
			color: #FFFFFF;
			line-height: 60rpx;
			text-align: center;
		}
	}

	.dial {
		.equipment_list {
			padding: 20rpx 30rpx;

			.equipment_item {
				margin-bottom: 0;
				padding: 0;

				.l {
					image {
						width: 130rpx;
						height: 130rpx;
						border-radius: 10rpx;
					}
				}
			}
		}
	}
</style>